package com.codeing.demo.task;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author shilei
 */
@Component
public class TaskDemo {
    private static final Logger log = LoggerFactory.getLogger(TaskDemo.class);

    /**
     * 测试分支提测
     */
    private static int count;

    @Scheduled(cron = "* * * * * ?")//每隔3秒去执行
    public void cron() {
        log.info("spring anno task execute times {}", count++);
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.MINUTE, 0);//0分
        cal.set(Calendar.SECOND, 0);//0秒
        cal.set(Calendar.MILLISECOND, 0);//0毫秒
        cal.set(Calendar.MINUTE, 0);//0分

        while (true) {
            System.out.println(System.currentTimeMillis()+"测试数据");
        }
    }

    public static void main(String[] args) {
        long l = System.currentTimeMillis();
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.SECOND, 0);//0秒
        cal.set(Calendar.MILLISECOND, 0);//0毫秒
        cal.set(Calendar.MINUTE, 0);//0分
        System.out.println(cal.getTimeInMillis());

        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");
        String format = simpleDateFormat.format(date);
        System.out.println(format);

    }
}
